import { _decorator, Color, color, Component, Graphics, Node, UITransform, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('DrawingLine')
export class DrawingLine extends Component {
    @property(Graphics)
    graphics: Graphics = null;

    drawingLine(posA: Vec3, posB: Vec3, color: Color, width: number) {
        this.graphics.clear();
        const localA: Vec3 = this.node.getComponent(UITransform)!.convertToNodeSpaceAR(posA);
        const localB: Vec3 = this.node.getComponent(UITransform)!.convertToNodeSpaceAR(posB);

        // 绘制线段
        this.graphics.lineWidth = width;
        this.graphics.strokeColor = color;

        this.graphics.moveTo(localA.x, localA.y);
        this.graphics.lineTo(localB.x, localB.y);
        this.graphics.stroke();
    }

}


